import 'package:json_annotation/json_annotation.dart';

part 'health_plan.g.dart';

@JsonSerializable()
class HealthPlan {
  final String? createTime;
  final String? updateTime;
  final Map<String, dynamic>? params;
  final int? id;
  final String? planAssort;
  final String? planName;
  final int? planCycle;
  final int? planProgress;
  final int? planPoints;
  final String? idDefault;
  final String? planStatus;
  final int? stepCount;
  final String? sleepQuality;
  final String? restingHeartRate;
  final String? heartRateVariability;
  final String? bloodOxygenSaturation;
  final String? calorie;
  final String? checkInEvent;
  final String? emotionManagement;
  final String? deviceSn;
  final int? userId;
  final String? isClaim;
  final String? startDate;
  final String? endDate;
  final String? earlyEndDate;

  HealthPlan({
    this.createTime,
    this.updateTime,
    this.params,
    this.id,
    this.planAssort,
    this.planName,
    this.planCycle,
    this.planProgress,
    this.planPoints,
    this.idDefault,
    this.planStatus,
    this.stepCount,
    this.sleepQuality,
    this.restingHeartRate,
    this.heartRateVariability,
    this.bloodOxygenSaturation,
    this.calorie,
    this.checkInEvent,
    this.emotionManagement,
    this.deviceSn,
    this.userId,
    this.isClaim,
    this.startDate,
    this.endDate,
    this.earlyEndDate,
  });

  factory HealthPlan.fromJson(Map<String, dynamic> json) => _$HealthPlanFromJson(json);
  Map<String, dynamic> toJson() => _$HealthPlanToJson(this);

  /// 获取计划状态文本
  String get statusText {
    switch (planStatus) {
      case '1':
        return '进行中';
      case '2':
        return '已生成';
      case '3':
        return '已完成';
      default:
        return '未知';
    }
  }

  /// 获取计划进度百分比
  double get progressPercentage {
    if (planCycle == null || planCycle == 0) return 0.0;
    return (planProgress ?? 0) / planCycle!;
  }

  /// 是否可以领取积分
  bool get canClaimPoints {
    return isClaim == '0' && planStatus == '3';
  }
}